import xlrd


def gen_table_model(r):
    if 'varchar' in r[3]:
        content = '{} = Column(String({})) # {}'.format(r[1], r[3].split(' ')[-1], r[2])

    # elif 'int' in r[2]:
    #     content = '{} = IntegerField(null=True) # {}'.format(r[0], r[1])
    # elif 'text' in r[2]:
    #     content = '{} = TextField(null=True) # {}'.format(r[0], r[1])
    # elif 'decimal' in r[2]:
    #     max, place = (r[2].split(' ')[-1]).split(',')
    #     content = '{} = DecimalField(null=True, max_digits={}, decimal_places={}) # {}'.format(r[0], max, place, r[1])
    else:
        content = ''
    return content


def gen_api_content(r):
    '''
    id:
        description: '角色ID'
        type: string
    '''
    content = ''
    content += "  description: '{}'\n".format(r[1])
    # print(r[3])
    if 'varchar' in r[3]:
        content += "  type: string"
    elif 'int' in r[2]:
        content += "  type: integer"
    elif 'text' in r[2]:
        content += "  type: string"
    else:
        content = ''
    return content


def gen_create(r):
    content = "{} = g.json.get('{}'), # {}".format(r[0], r[0], r[1])
    return content


file = 'boss_1.xlsx'

book = xlrd.open_workbook(file)
ProjectPublic = book.sheet_by_name('订单信息表')
FinancialIn = book.sheet_by_name('收入账单表')

for rx in range(ProjectPublic.nrows):
    # print(public.row(rx))
    r = ProjectPublic.row_values(rx)
    # print(r)
    # print(public.row_values(rx))
    # print(gen_create(r))
    print(gen_table_model(r))
    # print(gen_api_content(r))
